Open C: Directly with `FileStream` without `CreateFile` API

Posted by DxCK on Stack Overflow See other posts from Stack Overflow or by DxCK
Published on 2010-02-13T17:32:10Z Indexed on 2010/03/13 7:45 UTC
Read the original article Hit count: 294

Filed under:
|
|
|
|

I trying to open C: directly with FileStream without success:

new FileStream("C:", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

System.UnauthorizedAccessException was unhandled

Message="Access to the path 'C:\' is denied."

Source="mscorlib"

StackTrace:

  in  System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

  in  System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

  in  System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)

  in  System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

  in  ReadingMftNewTest.Program.Main(String[] args) in D:\CS\2008\ReadingMftNewTest\ReadingMftNewTest\Program.cs:line 76

Note that i openning "C:" but the error says "C:\", where did this slash came from? :\

Is there any chance to open C: without using the CreateFile API?

I really don't want be depending on WIN32 API because this code should also run on Mono that dont support WIN32 API, but successfully openning devices with regular FileStream (Mono 1 Microsoft 0).

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET